import {debounce} from "./utils";

/**
 * 防抖浑入
 * @type {{data(): {itemImgListener: null, newRefresh: null}, mounted(): void}}
 */
export const itemListenerMixin = {
  data(){
    return {
      itemImgListener: null,
      newRefresh:null
    }
  },
  mounted(){
    this.newRefresh = debounce(this.$refs.backTop.refresh,200);
    //定义一个闭包,每次都是一个单独的对象
    this.itemListenerMixin = () => {
      this.newRefresh();
    };
    this.$bus.$on("itemImageLoad",this.itemListenerMixin);
  }
};

/**
 * 回到顶部浑入
 * @type {{}}
 */
export const backTopMixin = {
  data(){
    return {
      position: false
    }
  },
  methods: {
    backTopClick(){
      this.$refs.backTop.scrollTo(0,0,2000);
    },
    listenShoBackTop(position){
      this.position = (position.y >= -1000) ?  false : true;
    }
  }
};
